package com.ether.controller;

import com.ether.entity.InvestName;
import com.ether.entity.MedCor;
import com.ether.entity.MedInvest;
import com.ether.mapper.MedInvestMapper;
import com.ether.util.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Controller
public class MedInvestController {

    @Autowired
    private MedInvestMapper medInvestMapper;

    @GetMapping("/")
    public String index(Model model) {
        return "index";
    }

    @GetMapping("/et")
    public String et(Model model) {
        return "et";
    }

    @GetMapping("/report")
    public String report(Model model) {
        return "report";
    }

    @GetMapping("/export")
    public void export(
            @RequestParam(value = "username") String username,
            @RequestParam(value = "comp") String comp,
            HttpServletResponse response
    ) throws IOException {
        List<MedInvest> medInvestList = medInvestMapper.findByCorname(username, comp);
        String fileName = "企业列表_" + System.currentTimeMillis();
        ExcelUtil.export(response, fileName, "企业数据", medInvestList, MedInvest.class);
    }

    @GetMapping("/exportInvestName")
    public void exportInvestName(
            HttpServletResponse response
    ) throws IOException {
        List<InvestName> investNameList = medInvestMapper.getInvestList();
        String fileName = "投资机构_" + System.currentTimeMillis();
        ExcelUtil.export(response, fileName, "投资机构", investNameList, InvestName.class);
    }

    @GetMapping("/exportMedCor")
    public void exportMedCor(
            HttpServletResponse response
    ) throws IOException {
        List<MedCor> medCorList = medInvestMapper.getMedCorList();
        String fileName = "医药企业_" + System.currentTimeMillis();
        ExcelUtil.export(response, fileName, "医药企业", medCorList, MedCor.class);
    }
}
